package com.datang.pet.api.commentController;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-06-15 19:07
 * @notify
 * @version 1.0
 */

import com.datang.pet.common.response.Result;
import com.datang.pet.common.utils.MD5;
import com.datang.pet.common.utils.StringUtils;
import com.datang.pet.service.CommentService;
import com.datang.pet.vo.AddLikeOneCommentRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AddLikeOneCommentController {
    @Autowired
    private CommentService commentService;

    @PostMapping("/addLikeOneComment")
    public Result addLikeOneComment(@RequestBody AddLikeOneCommentRequest addLikeOneCommentRequest) throws Exception {

        if (!StringUtils.isNUll(addLikeOneCommentRequest.getCommentUserId())) {
            throw new Exception("评论人id为空");
        }
        if (!StringUtils.isNUll(addLikeOneCommentRequest.getLikeCommentUserId())) {
            throw new Exception("点赞id为空");
        }
        if (!StringUtils.isNUll(addLikeOneCommentRequest.getTalkOneCommentId())) {
            throw new Exception("评论id为空");
        }
        if (!StringUtils.isNUll(addLikeOneCommentRequest.getType())) {
            throw new Exception("点赞type为空");
        }
        try {
            addLikeOneCommentRequest.setLikeCommentUserId(MD5.decryptData(addLikeOneCommentRequest.getLikeCommentUserId()));
        } catch (Exception e) {
            throw new Exception("userId解密出错！");
        }



        commentService.addLikeOneComment(addLikeOneCommentRequest);
        return Result.ok("成功");
    }
}
